package completablefuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @description: 并发编程 future
 * @author: WangPengPeng
 * @create: 2021-11-22 20:58
 **/
public class Demo1RunAsync {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Void> voidCompletableFuture = CompletableFuture.runAsync(() -> {
            try {
                Thread.sleep(2000);
                System.out.println("任务执行完成");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        // 阻塞，等待任务执行完成
        voidCompletableFuture.get();
        System.out.println("程序运行结束");
    }

}
